<template>
  <view class="partSelect">
    <partSelect
      :height="windowHeight"
      :safeAreaBottom="safeAreaBottom"
      ref="partSelect"
      @submit="submit"
    ></partSelect>
  </view>
</template>

<script>
import partSelect from './repair/components/group-select.vue';
export default {
	components: {
		partSelect,
	},
	onLoad() {
		console.log('[partSelect] onLoad ');
		uni.getSystemInfo({
			success: (res) => {
				setTimeout(() => {
					this.$nextTick(() => {
						this.windowHeight = res.windowHeight + 10;
						this.safeAreaBottom = this.windowHeight - res.safeArea.bottom;
					});
				}, 500);
			},
		});
		uni.getStorage({
			key: 'repairStatistical',
			success: (res) => {
				console.log('[partSelect] onLoad res:', JSON.stringify(res));
				this.allGroupIds = res.data.allGroupIds;
				this.allGroupTitles = res.data.allGroupTitles;
				this.$nextTick().then(() => {
					if (res.data.isFirst) {
						setTimeout(() => {
							this.$nextTick(() => {
								this.$refs.partSelect.initData({
									selectType: 2,
									selectArr: [],
									groupNames: [],
								});
							});
						}, 500);
					} else {
						setTimeout(() => {
							this.$nextTick(() => {
								this.$refs.partSelect.initData({
									selectType: 2,
									selectArr: res.data.id,
									groupNames: res.data.title,
								});
							});
						}, 500);
					}
				});
			},
		});
	},
	data() {
		return {
			windowHeight: 0,
			safeAreaBottom: 0,
			allGroupIds:[],// 所有组的ids，用于回显为空的时候展示
			allGroupTitles:[]// 所有组的ids，用于回显为空的时候展示
		};
	},
	methods: {
		submit(res) {
			console.log(res, '[partSelect] submit');
			uni.setStorage({
				key: 'repairStatistical',
				data: {
					id: res.selectArr,      // 回显的id
					title: res.groupNames, // 回显的名字
					isFirst: false,
					allGroupIds:this.allGroupIds,
					allGroupTitles:this.allGroupTitles
				},
				success: (res) => {
					console.log(res, '[partSelect] submit success');
					uni.navigateBack({});
					uni.$emit('setDatas', {});
				},
			});
		},
	},
};
</script>

<style lang="scss" scoped>
.partSelect {
}
</style>
